from ronglian_sms_sdk import SmsSDK
import json
import random

accId = '8a216da8762cb4570176f483b44f4661'
accToken = '2f2ae6c49fcf4e53b1d63fe9fb8e1544'
appId = '8a216da8762cb4570176f483b57a466f'


def send_message(phone):
    msg_code='%06d' %random.randint(0,1000000)
    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    mobile = phone  # 接收短信的手机号
    datas = (msg_code, '5')
    resp = sdk.sendMessage(tid, mobile, datas)
    print(resp)
    res_json = json.loads(resp)
    print(res_json.get('statusCode'))
    if res_json.get('statusCode') == '000000':
        return 1,msg_code
    else:
        return 0,None


if __name__ == '__main__':
    print(send_message('19801593972'))
